<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="java.util.*,java.io.*, java.sql.*, dbAccess.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Edit Patient Information</title>
<link rel="stylesheet" type="text/css" href="css_files/style.css" />
<script type="text/javascript">
function changeNumberofDays(code)
{
	var mylist;
	if (code == "1")
	{
		mylist = document.forms["frmSearchByRange"].cmbStartMonth;
	}
	else if (code == "2")
	{
		mylist = document.forms["frmSearchByRange"].cmbEndMonth;
	}
	else
	{
		mylist = document.forms["frmCreateAppt"].cmbMonth;
	}
	var month = mylist.selectedIndex;
	if ((month == 0) || (month == 2) || (month == 4) || (month == 6) || (month == 7) || (month == 9) || (month == 11))
	{
		var days;
		if (code == "1")
		{
			days = document.forms["frmSearchByRange"].cmbStartDate;
		}
		else if (code == "2")
		{
			days = document.forms["frmSearchByRange"].cmbEndDate;
		}
		else
		{
			days = document.forms["frmCreateAppt"].cmbDate;
		}
		days.options.length = 0;
		var i = 1;
		for (i = 1; i <= 31; i++)
		{
			var opt = document.createElement("option");
			days.options.add(opt);
			opt.text = i;
			opt.value = i;
		}
	}
	else if (month == 1)
	{
		var days;
		if (code == "1")
		{
			days = document.forms["frmSearchByRange"].cmbStartDate;
		}
		else if (code == "2")
		{
			days = document.forms["frmSearchByRange"].cmbEndDate;
		}
		else
		{
			days = document.forms["frmCreateAppt"].cmbDate;
		}
		days.options.length = 0;
		var i = 1;
		for (i = 1; i <= 28; i++)
		{
			var opt = document.createElement("option");
			days.options.add(opt);
			opt.text = i;
			opt.value = i;
		}
	}
	else
	{
		var days;
		if (code == "1")
		{
			days = document.forms["frmSearchByRange"].cmbStartDate;
		}
		else if (code == "2")
		{
			days = document.forms["frmSearchByRange"].cmbEndDate;
		}
		else
		{
			days = document.forms["frmSearchByRange"].cmbDate;
		}
		days.options.length = 0;
		var i = 1;
		for (i = 1; i <= 30; i++)
		{
			var opt = document.createElement("option");
			days.options.add(opt);
			opt.text = i;
			opt.value = i;
		}
	}
}
	
</script>
</head>
<body>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr>
    <td width="150" height="125" valign="top"><img src="images/caduceus.gif" alt="" name="LogoLeft" width="150" height="125" id="LogoLeft" style="background-color: #0033FF" /></td>
    <td width="692" align="center" valign="middle"><h1 align="center">CADUCEUS HOSPITAL </h1></td>
    <td width="157" valign="top"><img src="images/hospital.jpg" alt="" name="LogoRight" width="150" height="125" id="LogoRight" style="background-color: #0033FF" /></td>
  </tr>
  <tr>
     <td height="19" colspan="2" valign="top">Welcome <%=session.getAttribute("Name")%>&nbsp;<%=new java.util.Date() %></td>
	<td align="right"> 
		<a href="home.jsp" title="Logout">Logout</a>
	</td> 
  </tr>
</table>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr>
    <td width="259" valign="top"><p class="style2"><strong>Appointment Search </strong></p>      <form id="frmApptSearch" name="frmApptSearch" method="post" action="">
        <p>Year &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <select name="cmbYear" id="cmbYear">
            <option>2009</option>
          </select>
        </p>
        <p>Month &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <select name="cmbMonth" id="cmbMonth" onChange="changeNumberofDays()">
            <option>January</option>
            <option>February</option>
            <option>March</option>
            <option>April</option>
            <option>May</option>
            <option>June</option>
            <option>July</option>
            <option>August</option>
            <option>September</option>
            <option>October</option>
            <option>November</option>
            <option>December</option>
          </select>
        </p>
        <p>Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <select name="cmbDate" id="cmbDate">
            <option>1</option>
            <option>2</option>
            <option>3</option>
            <option>4</option>
            <option>5</option>
            <option>6</option>
            <option>7</option>
            <option>8</option>
            <option>9</option>
            <option>10</option>
            <option>11</option>
            <option>12</option>
            <option>13</option>
            <option>14</option>
            <option>15</option>
            <option>16</option>
            <option>17</option>
            <option>18</option>
            <option>19</option>
            <option>20</option>
            <option>21</option>
            <option>22</option>
            <option>23</option>
            <option>24</option>
            <option>25</option>
            <option>26</option>
            <option>27</option>
            <option>28</option>
            <option>29</option>
            <option>30</option>
            <option>31</option>
          </select>
        </p>
        <p>
          <input name="cmdSearch" type="submit" id="cmdSearch" value="Search" />
        </p>
    </form></td>
    
    <%
    String callerId = "patientListforStaff"; //set caller id
    String patientId = request.getParameter("pId").toString();
	
    //get SIN
	DbAccess access = new DbAccess();
	String query = "select tbl_patient.SIN from tbl_patient where tbl_patient.PatientId = " + patientId;
	String SIN = access.ExecuteScalar(access.connect(),query);
    %>
    
    <td width="740" rowspan="2" class="style2", valign="top"><h3 align="left"><span class="style5"><strong>Edit Patient Records</strong></span></h3>
    <form id="frmPatient" name="frmPatient" method="post" action="patientAddSave.jsp?action=update&callerId=<%=callerId %>&pId=<%=patientId%>">
            <%
            Login lgn = new Login();
    		ResultSet rs;
    		String firstName = "unknown";
    		String lastName = "unknown";
    		String emailAddress = "unknown";
    		String phoneNumber = "unknown";
    		String homeAddress = "unknown";
    		String gender = "unknown";
    		String dateOfBirth = "unknown";
    		int healthCard = 0;
    		int docId = Integer.parseInt(session.getAttribute("DocId").toString());

		//get patient information
		rs = lgn.getPatientInfo(Integer.parseInt(SIN));
		if (rs != null)
		{
			while (rs.next())
			{ 
				firstName = rs.getString("PatientFirstName");
				lastName = rs.getString("PatientLastName");
				emailAddress = rs.getString("tbl_patient.EmailAddress");
				phoneNumber = rs.getString("tbl_patient.Phone");
				homeAddress = rs.getString("tbl_patient.HomeAddress");
				gender = rs.getString("tbl_patient.Gender");
				dateOfBirth = rs.getString("tbl_patient.DateOfBirth");
				healthCard = rs.getInt("tbl_patient.HealthCard");
				docId = rs.getInt("tbl_patient.DocId");
			}
		}
	%>
    <table width="647">	
		<tr>
			<td width="117"><strong>
			  First Name
			  </strong></td>
		  <td width="518"><input name="fName" type="text" id="fName" value = <%=firstName%> />
		  </td>
		</tr>
				
		<tr>
			<td><strong>
			  Last Name
			</strong></td>
			<td><input name="lName" type="text" id="lName" value = <%=lastName%> /></td>
		</tr>
		<tr>
			<td><strong>
			  Email Address
			</strong></td>
			<td><input name="EmailAddress" type="text" id="EmailAddress" value = <%=emailAddress%> /></td>
		</tr>
				
		<tr>
			<td><strong>
			  Phone Number
			</strong></td>
			<td><input name="phoneNumber" type="text" id="phoneNumber" value = <%=phoneNumber%> /></td>
		</tr>
				
		<tr>
			<td><strong>
			  Home Address
			</strong></td>
			<td><input name="HomeAddress" type="text" id="HomeAddress" size = "128" value = <%=homeAddress%> /></td>
		</tr>
		<tr>
			<td><strong>
			  Date Of Birth
			</strong></td>
			<td><input name="DateOfBirth" type="text" id="DateOfBirth" value = <%=dateOfBirth%> /></td>
		</tr>
				
		<tr>
			<td><strong>
			  Gender
			</strong></td>
			<td>
				<%
					if (gender.equals("M"))
					{
				%>
					 <input name="gender" type="radio" value="male" checked/> Male
					 <input name="gender" type="radio" value="female"/> Female
				<%	
					}
					else
					{
				%>
					 <input name="gender" type="radio" value="male"/> Male
					 <input name="gender" type="radio" value="female" checked/> Female
				<%		
					}
				%>
			</td>
		</tr>
				
		<tr>
			<td>
			<strong>
			  Health Card Number
			</strong>
			</td>
			<td><input type="healthCardNum" name="healthCardNum" value = <%=healthCard%> />
			</td>
		</tr>
		<tr>
			<td>
			<strong>
			 	Default Doctor
			</strong>
			</td>
			<td>
				<select id="cmbDoctor" name="cmbDoctor">
					<%
						//obtain drop down list of all doctors in the system
						DbAccess access2 = new DbAccess();
						ResultSet rs2;
						int docId2;
						String docFirstName;
						String docLastName;
						String option;
						String query2 = "select tbl_doctor.DocId, tbl_doctor.FirstName, tbl_doctor.LastName ";
						query2 += "from tbl_doctor where tbl_doctor.IsDeleted = 0 ";
						query2 += "order by tbl_doctor.LastName";
						rs = access2.ExecuteSelect(access2.connect(), query2);
					if (rs != null)
					{
						while (rs.next())
						{
							docLastName = rs.getString("tbl_doctor.LastName").trim();
							docFirstName = rs.getString("tbl_doctor.FirstName").trim();
							docId2 = rs.getInt("tbl_doctor.DocId");
							option = docLastName + "," + docFirstName + "-" + docId2;
							
							if (docId2 == docId)
							{
							%>
								<option selected="selected"><%=option%></option>
							<%
							}
							else
							{
							%>
							<option><%=option%></option>
							
							<%
							}
						%>
					<%	
						}
					}
					%>
				</select>
			</td>
		</tr>
	</table>
    <p>&nbsp;</p> <p><input type="submit" name="cmdSave" id="cmdSave" value="Save"/>
    </p>
    </form>	
    </td>
  </tr>
  
  <tr>
    <td height="220" valign="top" class="style2"><p><strong>Quicklinks</strong></p>
    <p><a href="patient2appt.jsp">View My Appointments</a></p>
    <p><a href="editPatient.jsp">Change my Personal Information</a></p>
    <p><a href="http://www.webmd.com">WebMD</a></p>
    <p><a href="#">Last Visit</a></p>
    <p><a href="patientHome.jsp">Back to Homepage</a></p>
    <p>&nbsp;</p></td>
   </tr>
 </table>
</body>
</html>